/********************************************************************************
 * <PRE> * 파일 정보 *
 * 1. FileName	: GCMUtil.java
 * 2. Package	: com.ncomz.nzeip.common.util
 * 3. 설명        	: TODO
 * 4. 작성자		: P044826
 * 5. 작성일		: 2014. 5. 9. 오전 11:00:01
 * 6. 설명		:
 * </PRE>
 ********************************************************************************/


package com.sunny.hp.common.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.MulticastResult;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;

/********************************************************************************
 * <PRE> * 프로그램 정보 *
 * 1. Project		: bems20
 * 2. Package	: com.ncomz.nzeip.common.util
 * 3. FileName	: GCMUtil.java
 * 4. 작성자		: P044826
 * 5. 작성일		: 2014. 5. 9. 오전 11:00:01
 * 6. 설명			:
 * </PRE>
 ********************************************************************************/

public class GCMUtil {


	public static void sendMessage(GCMMessageInfo gcmMessageInfo) throws IOException {
		String GCM_SENDER = gcmMessageInfo.getServer_sender();
//		String MSG = gcmMessageInfo.getMessage();
		String MSG = gcmMessageInfo.getSendMessage();
//		Sender sender = new Sender("AIzaSyAEvWdlz-9rgoWGy-c8hPHFACfpZUpcH1I");
		Sender sender = new Sender(GCM_SENDER);

		//String regId = "APA91bGh5v5_HEITS-dzGaeHl925GPU58Aj-jv1GPtJbpXwev5VhG7ZYybAuMLAXt71hgHqI6pEmttKNrd29HiIhnMKN5TpZU6sdJKC3YbvsAZYQ4H8gPDXxMBbhXkWrEbcSDIAi3rWkSMiTxTTMZO5ObQnbYt24lQ";
//		Message message = new Message.Builder().addData("msg", "sk bems 서비상에 문제 발생 \n 데이터 확인 요청!!!").build();
		Message message = new Message.Builder().addData("msg", MSG).build();
		//List<String> list = new ArrayList<String>();
		List<String> list = gcmMessageInfo.getReceiverArray();
		//list.add(regId);

		MulticastResult multiResult = sender.send(message, list, 5);

		if (multiResult != null) {
			List<Result> resultList = multiResult.getResults();
			for (Result result : resultList) {
				System.out.println(result.getMessageId());
			}
		}
	}
}
